// pages/payment/sale/sale.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
http:getApp().globalData.map,
list:[],
index:'',
remake:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  wx.getStorage({
		  key:'uid',
		  success: (eve) => {
		  	wx.request({
		  		url:getApp().globalData.http+'action=returnAppShow&og_id='+options.id+'&uid='+eve.data.uid,
		  		success: (e) => {
		  			console.log(e)
					let a=e.data.data.thtype
					if(e.data.data.thtype==1){
						e.data.data.thtype='退货'
					}else if(e.data.data.thtype==2){
						e.data.data.thtype='换货'
					}else{
						e.data.data.thtype='仅退款'
					}
					this.setData({
						type:a,
						id:options.id,
						uid:eve.data.uid,
						data:e.data.data
					})
		  		}
		  	})
		  }
	  })
  },
  sc() {
  	let a = this.data.list
  	if (a.length < 9) {
  		let nan=9-a.length
  		wx.showToast({
  			title: '加载中',
  			icon: 'loading'
  		});
  		let that = this
  		wx.chooseImage({
  			count: nan,
  			sizeType: 'compressed',
  			success: (e) => {
  				e.tempFilePaths.forEach(function(item, index) {
  					wx.uploadFile({
  						url: getApp().globalData.http3,
  						filePath: e.tempFilePaths[index],
  						name: 'picturePath',
  						success: function(res) {
  							let c = JSON.parse(res.data)
  							a.push(c.data.headImage)
  							that.setData({
  								list: a
  							})
  							wx.hideToast();
  						}
  					});
  				})
  			}
  		})
  	}
  },
  dete(e) {
  	let a = this.data.list
  	a.splice(e.currentTarget.dataset.id, 1)
  	this.setData({
  		list: a
  	})
  },
  remake(e){
	  this.setData({
		  remake:e.detail.value
	  })
  },
  bindPickerChange(e) {
  	this.setData({
  		index: e.detail.value
  	})
  },
  sure(){
	  console.log(this.data.type+"===="+this.data.index+"===="+this.data.id+"===="+this.data.remake)
	  if(this.data.index!=''&&this.data.list.length!=0){
		  let c= this.data.data.thyy[this.data.index] +','+this.data.remake
		  console.log(c)
		  let a=this.data.list
		  a=a.join()
		  wx.request({
			  url:getApp().globalData.http+'action=returnApp&uid='+this.data.uid+'&og_id='+this.data.id+'&type='+this.data.type
			  +'&remark='+c+'&pic='+a,
			  success: (e) => {
				wx.showToast({
					title:e.data.msg,
					icon:'none',
					success: () => {
						wx.navigateBack({delta:2})
					}
				})
			  }
		  })
	  }else{
		  wx.showToast({
			  title:'请正确填写信息',
			  icon:'none'
		  })
	  }
  }
})